<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <p>全部评论</p>   
    <p>好评</p>
    <p>有视频</p>

    <script>

        var oPs = document.querySelectorAll('p') ;

        for(var i = 0 ; i < oPs.length ; i++) {
            // 给每一个p对象添加一个sex属性
            oPs[i].sex = i ;

            
            oPs[i].onclick = function() {
                console.log(this.sex);
            }
        }

    </script>
    
</body>
</html>